home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Extensions… / UserAlert ƒ / UserAlert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  3.9 KB  |  161 lines  |  [TEXT/MPS ]

  1. /*________________________________________________________
  2.  
  3.     File: UserAlert.c
  4.  
  5.     C code for a printing extension that adds an alert
  6.     item to the desktop printer menu and displays the alert
  7.     during despooling.
  8.  
  9.     Dave Hersey
  10.     Apple Developer Technical Support
  11.  
  12.     12/01/92     - dmh - created.
  13.     12/22/93     - dmh - updated for b3.
  14.      5/03/94     - dmh - updated for f2.
  15.      6/14/96    - cn  - Updated to support Universal Interfaces 2.1.
  16.  
  17.     (Note: all functions are in the Mark menu.)
  18.     
  19. __________________________________________________________*/
  20.  
  21. #include <Types.h>
  22. #include <Errors.h>
  23. #include <Resources.h>
  24. #include <ToolUtils.h>
  25. #include <GXPrinting.h>
  26. #include <GXExceptions.h>
  27.  
  28. #include "UserAlert.h"
  29.  
  30. /*******************************************************************
  31.     NewGetDTPMenuList is our override for GXGetDTPMenuList.  All we
  32.     do is add our item to the DTP printer menu and forward the
  33.     message.
  34.     
  35. ********************************************************************/
  36.  
  37. OSErr NewGetDTPMenuList(MenuHandle aMenu)
  38. {
  39.     OSErr            err1, err2;
  40.     StringHandle    itemStr;
  41.  
  42. // Get our menu item's name and append it to the desktop printer menu.
  43.  
  44.     itemStr = (StringHandle) GetString(r_AlertString);
  45.     err1 = ResError();
  46.     
  47.     if (err1 == noErr)
  48.     {
  49.         HLock((Handle) itemStr);
  50.         AppendMenu(aMenu, (ConstStr255Param) *itemStr);
  51.         ReleaseResource((Handle) itemStr);
  52.     }
  53.  
  54.     err2 = Forward_GXGetDTPMenuList(aMenu);
  55.     
  56.     if (err1 == noErr)
  57.         err1 = err2;
  58.  
  59.     return err1;
  60. }
  61.  
  62.  
  63. /*******************************************************************
  64.     NewDTPMenuSelect is our override for GXDTPMenuSelect.  If our
  65.     DTP printer menu item is selected, we just put up an alert.
  66.     Otherwise:
  67.     
  68.     If the menu item passed is < 1 we forward it.  If it's greater
  69.     than the number of items we added, we subtract the number of
  70.     items we added before forwarding.
  71.     
  72. ********************************************************************/
  73.  
  74. OSErr NewDTPMenuSelect(short itemID, Boolean *done)
  75. {
  76.     OSErr                err = noErr;
  77.     gxStatusRecord        *pStatus;
  78.  
  79.     // If itemID < 1, this is a GX-added menu item.  Forward as is.
  80.  
  81.     if (itemID < 1)
  82.         err = Forward_GXDTPMenuSelect(itemID);
  83.     else
  84.         switch (itemID)
  85.         {
  86.             case kAlertItem:  // Our alert item.
  87.     
  88.                 pStatus = (gxStatusRecord *)
  89.                             NewPtrClear(sizeof(gxStatusRecord) + sizeof(short));
  90.     
  91.                 require_action(pStatus, CantMakeStatusRecord , err = MemError(););
  92.                 
  93.     // Fill in the status record appropriately.
  94.  
  95.                 pStatus->statusOwner    = kCreator;
  96.                 pStatus->statResId        = kUserAttentionID;
  97.                 pStatus->statResIndex    = kAlertStatusIdx;
  98.  
  99.     // Continue alerting the user until s/he responds.
  100.     
  101.                 do
  102.                 {
  103.                     err = GXAlertTheUser(pStatus);
  104.                 }
  105.                 while ((err == noErr) && (pStatus->dialogResult == 0));
  106.     
  107.                 *done = true;
  108.                 DisposPtr((Ptr) pStatus);
  109.                 break;
  110.     
  111.             default:
  112.                 err = Forward_GXDTPMenuSelect(itemID -kNumMenuItemsWeAdded);
  113.         }
  114.  
  115. CantMakeStatusRecord:
  116.     return err;
  117. }
  118.  
  119.  
  120. /*******************************************************************
  121.     NewDespoolPage is our override for GXDespoolPage.      Here, we
  122.     despool the desired page & format and then display an alert.
  123.  
  124. ********************************************************************/
  125.  
  126. OSErr NewDespoolPage(gxSpoolFile thePrintFile, long pageNumber,
  127.                      gxFormat pageFormat, gxShape *pagePicture,
  128.                      Boolean *formatChanged)
  129. {
  130.     OSErr                err;
  131.     gxStatusRecord        *pStatus;
  132.     
  133.     err = Forward_GXDespoolPage(thePrintFile, pageNumber,
  134.                                 pageFormat, pagePicture, formatChanged);
  135.  
  136.     nrequire(err, FailedForward_GXDespoolPage);
  137.     pStatus = (gxStatusRecord *) NewPtrClear(sizeof(gxStatusRecord));
  138.     require_action(pStatus, CantMakeStatusRecord, err = MemError(););
  139.         
  140. // Fill in the status record appropriately.
  141.  
  142.     pStatus->statusOwner    = kCreator;
  143.     pStatus->statResId        = kUserAttentionID;
  144.     pStatus->statResIndex    = kAlertStatusIdx;
  145.  
  146. // Continue alerting the user until s/he responds.
  147.  
  148.     do
  149.     {
  150.         err = GXAlertTheUser(pStatus);
  151.     }
  152.     while ((!err) && (pStatus->dialogResult == 0));
  153.  
  154.     DisposPtr((Ptr) pStatus);
  155.  
  156. CantMakeStatusRecord:
  157. FailedForward_GXDespoolPage:
  158.     return err;
  159. }
  160.  
  161.